package com;

import com.fz.dao.BookDAO;
import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017-09-11.
 */
public class Demo {
    @Test
    public void dao(){
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookDAO bdao = ctx.getBean(BookDAO.class);
        //BookDAO bdao = ctx.getBean("bdao",BookDAO.class);
        //Book book = bdao.queryById(12);
        //System.out.println(book);

        bdao.deleteById(12);

        List<Book> list = bdao.queryAll();
        for(Book bk : list){
            System.out.println(bk);
        }



        ctx.close();
    }



    @Test
    public void mm(){
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookMapper bdao = ctx.getBean(SqlSession.class).getMapper(BookMapper.class);
        //Book bk = bdao.queryById(6);
        //System.out.println(bk);

        //Book bk = new Book();
        //bk.setName("《java案例》");
        //bk.setPrice(80);
        //bk.setBdate(new Date());
        //bdao.save(bk);

        List<Map<String,Object>> list = bdao.query();
        System.out.println(list.size());
        for(Map<String,Object> m : list){
            System.out.println(m.get("id"));
            System.out.println(m.get("name"));
            System.out.println(m.get("price"));
        }

        ctx.close();
    }

}
